<template>
  <div class="app-container">
    <div class="filter-container">
        
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="ID" width="80" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
 
      <el-table-column min-width="100px" label="名称" align="center">
        <template slot-scope="{row}">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80px" label="快递编码" align="center">
        <template slot-scope="{row}">
          <span>{{ row.code }}</span>
        </template>
      </el-table-column> 

      <el-table-column width="200px" align="center" label="添加时间">
        <template slot-scope="scope">
          <span>{{ scope.row.createAt | parseTimeFormat('YYYY-MM-DD HH:mm:ss') }}</span>
        </template>
      </el-table-column>

      <el-table-column align="left" label="操作" max-width="100">
        <template slot-scope="scope">
          <router-link :to="'/delivery/edit/'+scope.row.id">
            <el-button type="primary" size="small" icon="el-icon-edit" style="margin-right:10px">编辑</el-button>
          </router-link>
          <el-button
            @click="deleteDelivery(scope.row.id)"
            size="small"
            type="danger"
            icon="el-icon-delete"
          >删除</el-button>
        </template>
      </el-table-column> 
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :current-page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @pagination="changePage"
    />

  </div>
</template>

<script>
import { deliveryList, deliveryDelete } from "@/api/delivery";
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination


export default {
  name: "DeliveryList",
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        status: null,
        paid: null,
        pageNo: 0,
        pageSize: 10,
        pageType: "P"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取订单列表
    getList() {
      this.listLoading = true;
      deliveryList(this.listQuery).then(response => {
        this.list = response.data;
        this.total = response.count;
        this.listLoading = false;

        console.log('list', this.list);
      });
    },
    // 删除
    deleteDelivery(id) {
        let that = this;

        this.$confirm('此操作将删除该快递, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            deliveryDelete({ id:id }).then(res => {
                if (res.success == true) {
                    this.$notify({
                        title: "删除成功",
                        message: "删除快递成功",
                        type: "success",
                        duration: 2000
                    });
                    that.getList();
                }
            });
        }).catch(() => {
            return false;      
        });
    },
    handleFilter() {
      this.listQuery.pageNo = 0;
      this.getList();
    },
    // 分页
    changePage(value) {
      this.listQuery.pageNo = value.page - 1;
      this.listQuery.pageSize = value.limit;
      this.getList();
    },
    // 页码或者当前页发生变化
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.listQuery.pageNo = val - 1;
      this.getList();
    },
  }
};
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
  
}
label{font-weight: normal !important ;}
</style>
